package com.yishun.springboot.service;

import java.security.NoSuchAlgorithmException;
import java.text.ParseException;
import java.util.List;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;
import com.yishun.springboot.mapper.GwsPushDataMapper;
import com.yishun.springboot.pojo.GwsPushData;

import lombok.extern.slf4j.Slf4j;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.util.StringUtils;

/**
 * 上传工务署实名制-班组
 *
 * @author XiaoHuang
 * @date 2021年5月11日上午9:23:00
 */

@Slf4j
@Service
@Component
//@SpringBootTest
//@RunWith(SpringRunner.class)
public class GongWuSuTimedUploadCWSTeamInfoService {

    @Autowired
    GongWuSuUploadCWSService gongWuSuUploadCWSService;

    @Autowired
    GwsPushDataMapper gwsPushDataMapper;

    //定时上传班组
    //注意同步好这3个表：yzwteammaster、yzwworkerlist、yzwsubcontractorlist就行，程序会自动对应表gws_team
    @Async(value = "asyncExecutor")
    @Scheduled(fixedRate = 4 * 60 * 60 * 1000)
//    @Test
    public void uploadTeamInfoData() throws NoSuchAlgorithmException, ParseException {
        List<GwsPushData> gpdList = gwsPushDataMapper.selectAllRecord();
        GwsPushData gpd = null;

        String gwsProjectCode = null;
        Integer yzwProjectCode = null;
        String projectName = null;
        for (int i = 0; i < gpdList.size(); i++) {
            gpd = gpdList.get(i);
            gwsProjectCode = gpd.getGwsProjectCode();
            yzwProjectCode = gpd.getYzwProjectCode();
            projectName = gpd.getProjectName();

            if (StringUtils.isEmpty(gwsProjectCode) || yzwProjectCode == null || StringUtils.isEmpty(projectName)) {
                continue;
            }
            gongWuSuUploadCWSService.uploadTeam(gwsProjectCode, yzwProjectCode, projectName);//上传班组
        }
    }
}
